package com.example;

import com.example.config.SpringConfig;
import com.example.service.BookService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BookApp {
    //1.注解定义bean测试
    @Test
    public void testIOCBean(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = applicationContext.getBean(BookService.class);
        System.out.println(bookService);
        bookService.save();
    }


    //2.注解注入bean
    @Test
    public void testDIBean(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = applicationContext.getBean(BookService.class);

        System.out.println(bookService);
        bookService.save();
    }

    @Test
    public void testZhuj(){
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        BookService bean = annotationConfigApplicationContext.getBean(BookService.class);
        bean.save();
    }
}
